<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /* 
    web存储：cookie   localStorage   sessionStorage
       cookie:有时间限制  存储大小：几Kb
       localStorage:没有时间限制，只要不手动清除就一直存在     存储大小：几Mb
       sessionStorage:没有时间限制，页面关闭后自动清除    存储大小：几Mb
    */
</script>
<script>
    /* 
     localStorage和sessionStorage的方法：
           1、 存数据setItem(key,value)  value只能是基本数据类型
    */
   console.log(localStorage.setItem('key1','value1'));
   console.log(localStorage.setItem('key2','value2'));
//    JSON.stringify()  将JSON对象转化为字符串
var obj = {
    name:'zs'
}
localStorage.setItem('obj',JSON.stringify(obj))
        //  2、取数据getItem(key)
        console.log(localStorage.getItem('key1'));
        JSON.parse(localStorage.getItem('obj'))
        // console.log(localStorage.clear());
        // 3、移出数据removeItem(key)
        console.log(localStorage.removeItem('key1'));
        // 4、清除数据clear()
        // console.log();
        localStorage.clear()
</script>
</html>